﻿using System;
using System.Collections.Generic;
using System.Text;
using net.veekee.common;
using System.Reflection;

namespace net.veekee.common.data
{
    [Serializable]
    public class AnEntry
    {
        public ulong Line { get; set; }
        public String Archive { get; set; }
        public String Filename { get; set; }

        private FieldManager fields = null;
        public FieldManager Fields
        {
            get
            {
                return this.fields;
            }
        }

        private List<String> triggeredRules = null;
        public List<String> TriggeredRules
        {
            get
            {
                return this.triggeredRules;
            }
        }

        public String FullData = "";

        public AnEntry()
        {
            this.fields = new FieldManager();
            this.triggeredRules = new List<String>();
        }

        public void Load(Dictionary<int, String> header, List<String> csv)
        {
            int lcsv = csv.Count;
            for (int col = 0; col < header.Count && col < csv.Count; col++)
            {
                this.fields.Set(header[col], csv[col]);
            }
            for (int col = header.Count; col < csv.Count; col++)
            {
                this.fields.Set("Unknown_" + col, csv[col]);
            }
        }

        public List<Object> Dump()
        {
            return this.Fields.Dump();
        }

        public String GetTriggeredRules()
        {
            StringBuilder sb = new StringBuilder();
            String sep = "";
            foreach (String rule in this.triggeredRules)
            {
                sb.Append(rule);
                if (sep.Length == 0)
                    sep = ", ";
                sb.Append(sep);
            }
            return sb.ToString();
        }

        public override string ToString()
        {
            return String.Format("#{0} => {1}", this.Line, this.FullData);
        }
    }
}
